package com.ruoyi.service;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.service.BaseServiceImpl;
import com.ruoyi.entity.SysUserGroup;
import com.ruoyi.mapper.SysUserGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 【请填写功能名称】Service业务层处理
 * @date 2023-03-16
 */
@Service
public class SysUserGroupServiceImpl extends BaseServiceImpl<SysUserGroupMapper, SysUserGroup>
{
    @Autowired
    private SysUserGroupMapper sysUserGroupMapper;

    public SysUserGroup selectSysUserGroupById(Long id)
    {
        return sysUserGroupMapper.selectById(id);
    }

    public List<SysUserGroup> selectSysUserGroupList(SysUserGroup sysUserGroup)
    {
        return sysUserGroupMapper.selectSysUserGroupList(sysUserGroup);
    }

    public int insertSysUserGroup(SysUserGroup sysUserGroup)
    {
        this.saveOrUpdate(sysUserGroup);
        return 1;
    }

    public int updateSysUserGroup(SysUserGroup sysUserGroup)
    {
        return sysUserGroupMapper.updateById(sysUserGroup);
    }

    public int deleteSysUserGroupByIds(Long[] ids)
    {
            sysUserGroupMapper.deleteBatchIds(Arrays.asList(ids));
        return 1;
    }
    
    public int deleteSysUserGroupById(Long id)
    {
        return sysUserGroupMapper.deleteById(id);
    }

    public List<SysUser> getGroupUserList(Long userId) {
        return sysUserGroupMapper.getGroupUserList(userId);
    }

    public String getGroupUserStr(Long userId) {
        List<SysUser> list = sysUserGroupMapper.getGroupUserList(userId);
        return list.stream().map(SysUser::getUserIdStr).collect(Collectors.joining(","));
    }
}
